package com.hundsun.yr.universal.p2p.utils;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;


/**
 * @Title: VolleyHelper.java 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @date 2015-10-14 下午6:13:22 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class VolleyHelper {
    private RequestQueue requestQueue = null;

    private static volatile VolleyHelper instance = null;

    private VolleyHelper() {
    }

    public static VolleyHelper getInstance() {
        if (null == instance) {
            synchronized (VolleyHelper.class) {
                if (null == instance) {
                    instance = new VolleyHelper();
                }
            }
        }
        return instance;
    }

    /**
     * 初始化requestQueue
     *
     * @param context
     */
    public void init(Context context) {
        requestQueue = Volley.newRequestQueue(context); 
    }

    /**
     * 获取requestQueue
     *
     * @return
     */
    public RequestQueue getRequestQueue() {
        if (null != requestQueue) {
            return requestQueue;
        } else {
            throw new IllegalArgumentException("RequestQueue is not initialized.");
        }
    }
    
    /**
     * 清空volley缓存
     */
    public void clearCache(){
    	if (null != requestQueue) {
    		requestQueue.getCache().clear();
        } 
    }
}
